﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using DingTalkAgent.DBUtility;
using System.Data.SqlClient;
using System.Reflection;
using DingTalkAgent.Model;

namespace DingTalkAgent.SqlData
{
    public class T_CustomerRepository
    {
        public DataSet GetCustomerList(int page,int rows,string q)
        {
            page = (page - 1) * rows;
            IDataParameter[] param = new SqlParameter[3];
            param[0]= new SqlParameter("@p_page", page);
            param[1] = new SqlParameter("@p_rows", rows);
            param[2] = new SqlParameter("@p_q", q);
            return DbHelperSQL.RunProcedure("getCustomerList", param, "Customer");
        }

        public int Save(T_Customer mod)
        {
            int result = 0;

            IDataParameter[] param = new SqlParameter[7];
            param[0] = new SqlParameter("@p_id", mod.id);
            param[1] = new SqlParameter("@p_name", mod.name);
            param[2] = new SqlParameter("@p_telephone", mod.telephone);
            param[3] = new SqlParameter("@p_address", mod.address);
            param[4] = new SqlParameter("@p_source", mod.source);
            param[5] = new SqlParameter("@p_intentService", mod.intentService);
            param[6] = new SqlParameter("@p_saleUserId", mod.saleUserId);
            DbHelperSQL.RunProcedure("AddOrEditCustomer", param, out result);
            return result;
        }

        public DataSet GetArchivesList(int page, int rows, int id)
        {
            page = (page - 1) * rows;
            IDataParameter[] param = new SqlParameter[3];
            param[0] = new SqlParameter("@p_page", page);
            param[1] = new SqlParameter("@p_rows", rows);
            param[2] = new SqlParameter("@p_id", id);
            return DbHelperSQL.RunProcedure("GetArchivesList", param, "Archives");
        }

        public int SaveArchives(T_MedicalArchives mod)
        {
            int result = 0;

            IDataParameter[] param = new SqlParameter[6];
            param[0] = new SqlParameter("@p_id", mod.id);
            param[1] = new SqlParameter("@p_hospitalName", mod.hospitalName);
            param[2] = new SqlParameter("@p_medicalTime", mod.medicalTime);
            param[3] = new SqlParameter("@p_remarks", mod.remarks);
            param[4] = new SqlParameter("@p_createUser", mod.createUser);
            param[5] = new SqlParameter("@p_customerId", mod.customerId);
            DbHelperSQL.RunProcedure("AddOrEditMedicalArchives", param, out result);
            return result;
        }
    }
}
